package com.gp.controller.order;

import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.gp.common.result.JsonResult;
import com.gp.common.utils.CookieUtils;
import com.gp.controller.BaseController;
import com.gp.model.dto.AccountDto;
import com.gp.service.IBaseOrdergoodsService;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 弓成龙
 * @since 2017-11-26
 */
@RestController
@RequestMapping("/orderGoods")
public class BaseOrdergoodsController extends BaseController {

  @Autowired
  private IBaseOrdergoodsService orderGoodsService;

  /**
   * 结算： 删除购物车中的商品，同时将商品放到orderGoods 表中
   * 
   * @param account
   * @return
   */
  @RequestMapping(value = "/account", method = RequestMethod.POST)
  public JsonResult account(@RequestBody AccountDto[] account) {
    String ordercode = orderGoodsService.account(Arrays.asList(account),
        CookieUtils.obtainCurrentUser(CookieUtils.getCurrentRequest()));
    return renderSuccess("结算成功", ordercode);
  }
}
